package top.byfree.jbyan.saber.common

import org.springframework.stereotype.Component
import top.byfree.jbyan.saber.bean.VerificationCode
import java.util.concurrent.ConcurrentHashMap

/**
 * 验证码存储上下文
 *
 * @author jbyan
 * @since 25/3/2024
 */
@Component
class VerificationContext {

    /* 验证码缓存 */
    private val codeContext = ConcurrentHashMap<String, VerificationCode>()


    fun getCode(email: String): VerificationCode? = codeContext[email]


    fun setCode(email: String, verificationCode: VerificationCode) {
        codeContext[email] = verificationCode
    }

    fun removeCode(email: String) = codeContext.remove(email)


}